import {reactive, ref} from "vue";
import {getRoleList} from "../../api/options";
import {useStore} from "vuex";
interface CuPickerOpt {
    value: string
    label: string
}

export function useRoleOpts(){

    const {state} = useStore()
    const roleOpts = reactive<CuPickerOpt[]>([])

    getRoleList(state.user.userInfo.CUSER_ID).then(res => {
        if (res.ERROR[0].errcode == '0'){
            roleOpts.push(...res.DAT.map(item => ({
                value: item.ROLE_ID + '',
                label: item.ROLENAME
            })))
        }else {
            uni.showToast({
                title: res.ERROR[0].error,
                icon: 'none',
                mask: true
            })
        }
    }).catch(err => {
        uni.showToast({
            title: '获取角色列表失败',
            icon: 'none',
            mask: true
        })
    })

    return {
        roleOpts
    }
}
